<script language="JavaScript">
$('#cancelBtn').click(function () {
    var index = parent.layer.getFrameIndex(window.name);
    parent.layer.close(index);
});

$("#submit-form").validator({
    submit: function() {
        if(this.isFormValid()) {
            var rightBox = $('[data-eyetype="right"]');
            var leftBox = $('[data-eyetype="left"]');
            var product_id = $('#product_id').val();
            if(!product_id) {
                layer.alert("产品信息出错了");return false;
            }
            var _eye_data = [];
            var _data = {};
            _data['sph'] = rightBox.find('[name="sph"]').val();
            _data['cyl'] = rightBox.find('[name="cyl"]').val();
            _data['add'] = rightBox.find('[name="add"]').val();
            _data['suggested_price'] = Number(rightBox.find('[name="suggested_price"]').val());
            _eye_data.push(_data);

            var _data = {};
            _data['sph'] = leftBox.find('[name="sph"]').val();
            _data['cyl'] = leftBox.find('[name="cyl"]').val();
            _data['add'] = leftBox.find('[name="add"]').val();
            _data['suggested_price'] = Number(leftBox.find('[name="suggested_price"]').val());
            _eye_data.push(_data);

            $.post(location.href, {'product_id':product_id, 'eye_data': JSON.stringify(_eye_data)}, function (res) {
                if(res.code == 1) {
                    layer.alert(res.msg);return false;
                }
                var rtn = res.data;
                for ( var index in rtn) {
                    rtn[index].data_type = "goods";
                    var arryString = [];

                    rtn[index].name = productGroupName(rtn[index].Products);
                    /************二级参数**********************/
                    rtn[index].subparams = [];
                    if (rtn[index].Products.TypeId == 10) {
                        rtn[index].subparams.push(rtn[index].Snd.sph);
                        rtn[index].subparams.push(rtn[index].Snd.cyl);
                    } else if (rtn[index].Products.TypeId == 30) {
                        rtn[index].subparams.push(rtn[index].Snd.model);
                        rtn[index].subparams.push(rtn[index].Snd.color);
                        if (rtn[index].Snd.size) {
                            rtn[index].subparams.push(rtn[index].Snd.size);
                        }
                    } else if (rtn[index].Products.TypeId == 41) {
                        rtn[index].subparams.push(rtn[index].Snd.model);
                        rtn[index].subparams.push(rtn[index].Snd.color);
                        if (rtn[index].Snd.size) {
                            rtn[index].subparams.push(rtn[index].Snd.size);
                        }
                        if (rtn[index].Snd.function_info) {
                            rtn[index].subparams.push(rtn[index].Snd.function_info);
                        }
                    } else if (rtn[index].Products.TypeId  == 40) {
                        rtn[index].subparams.push(rtn[index].Snd.sph);
                        rtn[index].subparams.push(rtn[index].Snd.add);
                    } else if (rtn[index].Products.TypeId  == 20) {
                        rtn[index].subparams.push(rtn[index].Snd.sph);
                        rtn[index].subparams.push(rtn[index].Snd.cyl);
                    }
                    parent.addGoods(rtn[index]);
                }
            }, 'json');
        }
        return false;
    }
});
</script>